#include "ViewableComponent.h"
#include "PositionalComponent.h"


ViewableComponent::ViewableComponent(void)
{
	model = Utilities::useModel("Tank.aml");
	unique_ID = Utilities::generateIdentifier();
}

ViewableComponent::ViewableComponent(string fname)
{
	model = Utilities::useModel(fname);
	unique_ID = Utilities::generateIdentifier();
	hovered = false;
}

ViewableComponent::~ViewableComponent(void)
{
}

void ViewableComponent::initMe(GameComponent* parent)
{
	parent->setProperties(VIEWABLE);
	entity_position = ((PositionalComponent*)parent->getComponent(POSITIONED))->getPos();
	shader = Utilities::useShader("default.shader");
	hshader = Utilities::useShader("hovered.shader");
	//glUseProgram(shader);
}

void ViewableComponent::renderMe(AlphaMatrixStack* mv, AlphaMatrix* proj)
{
	mv->pushMatrix();
		mv->translate(entity_position->getX(), entity_position->getY(), entity_position->getZ());
		float lpos[] = {1000.0f, 1000.0f, 1000.0f, 1.0f};

		//glUseProgram(shader);
		if(hovered)
		{
			glUseProgram(hshader);
			int ui = glGetUniformLocation(shader,"ID");
			glUniform1f(ui, unique_ID);
			model->display(&mv->getMatrix(), proj, lpos, hshader);
		}
		else
		{
			glUseProgram(shader);
			int ui = glGetUniformLocation(shader,"ID");
			glUniform1f(ui, (float)unique_ID);
			model->display(&mv->getMatrix(), proj, lpos, shader);
		}
		
	mv->popMatrix();
	hovered = false;
}
